﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Fabrication.ValueProviders
{
    internal sealed class GenericListProvider : IValueProvider
    {
        private static readonly Type listType = typeof(List<>);
        private Type genericListType;

        public void Initialize(PropertyInfo property)
        {
            var itemType = property.PropertyType.GetGenericArguments().Single();
            genericListType = listType.MakeGenericType(itemType);
        }

        object IValueProvider.GetValue(object item)
        {
            return Activator.CreateInstance(genericListType);
        }
    }
}